package org.kealinghornets.jchuah.buttons;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;


public class MainActivity2 extends MainActivity {

    public void checkVictory() {
        View left_purple = findViewById(R.id.left_purple);
        View right_purple = findViewById(R.id.right_purple);
        View middle_purple = findViewById(R.id.middle_purple);
        View new_purple = findViewById(R.id.new_purple);
        if(left_purple.getVisibility() == View.INVISIBLE && right_purple.getVisibility() == View.INVISIBLE && middle_purple.getVisibility() == View.INVISIBLE && new_purple.getVisibility() == View.INVISIBLE) {
            Toast.makeText(this, "YOU WIN :)! - Dodie", Toast.LENGTH_LONG).show();
            startActivity(new Intent(this, MainActivity3.class));
        }

    }

    public void toggleVisibility(int id) {
        View left_purple;
        View right_purple;
        View middle_purple;
        View new_purple;

        left_purple = findViewById(id);

        if (left_purple.getVisibility() == View.VISIBLE) {
            left_purple.setVisibility(View.INVISIBLE);
        } else {
            left_purple.setVisibility(View.VISIBLE);
        }
    }

    public void onButton_LeftPush(View view) {
        Log.d("YourFace", "LEFT BUTTON IS BEING PUSHED!!!! Hi - Dodie");
        Toast.makeText(this, "You are now L33T H4x0R", Toast.LENGTH_SHORT).show();
        toggleVisibility(R.id.left_purple);
        toggleVisibility(R.id.right_purple);
        checkVictory();
    }

        public void onButton_MiddlePush(View view) {
            Log.d("YourFace"  , "MIDDLE BUTTON IS BEING PUSHED!!!! Hi - Dodie");
            Toast.makeText(this, "Toast sandwich", Toast.LENGTH_SHORT).show();
            toggleVisibility(R.id.middle_purple);
            toggleVisibility(R.id.right_purple);
            checkVictory();
        }
        public void onButton_RightPush(View view) {
            Log.d("YourFace"  , "RIGHT BUTTON IS BEING PUSHED!!!! Hi - Dodie");
            Toast.makeText(this, "Good job. You pressed a button.", Toast.LENGTH_SHORT).show();
            toggleVisibility(R.id.new_purple);
            toggleVisibility(R.id.left_purple);
        checkVictory();
        }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_activity2);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main_activity2, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
